<template>
  <div class="outer">
    <section class="main">
      <div class="banner">
        <back-btn></back-btn>
        <!--<img src="../../assets/images/newImg/flight/bannerplane.png"/>-->
      </div>
      <div class="listInfo">
        <div class="way-and-reutren">
          <div @click="setistrip(1)"><span :class="{spanaactive:istrip==1}">单程</span></div>
          <div @click="setistrip(2)"><span :class="{spanaactive:istrip==2}">往返</span></div>
        </div>
        <div class="planeInfo">
          <div class="plane-box">
            <exchange-city :cityGo="cityGo"
                           :cityBack="cityBack"
                           :cityGoObj="cityGoClassObj"
                           :cityBackObj="cityBackClassObj"
                           @selectCityGo="cityVue"
                           @selectCityBack="cityVue"
                           @exchangeCity="change"></exchange-city>
            <date-select :isShowDateTo="istrip === 2"
                         :calendarFromData="calendarFromData"
                         :weekFromData="weekFromData"
                         :calendarToData="todate"
                         :weekToData="toweeks"
                         @dateFromSelect="popupFromCalendarVisible = true"
                         @dateToSelect="popupToCalendarVisible = true"></date-select>
            <div v-transfer-dom>
              <Popup v-model="popupFromCalendarVisible" position="bottom" max-height="50%" style="background: none">
                <inline-calendar
                  @on-select-single-date="onChangeFromDate"
                  :show.sync="show"
                  v-model="calendarFromData2"
                  :start-date="startDate"
                  :end-date="endDate"
                  :show-next-month="false"
                  :show-last-month="false"
                  :replace-text-list="{'TODAY':'今'}">
                </inline-calendar>
              </Popup>
            </div>
            <div v-transfer-dom>
              <Popup v-model="popupToCalendarVisible" position="bottom" max-height="50%" style="background: none">
                <inline-calendar
                  @on-select-single-date="onChangeToDate"
                  :show.sync="show"
                  v-model="calendarToData2"
                  :start-date="startDate2"
                  :end-date="endDate"
                  :show-next-month="false"
                  :show-last-month="false"
                  :replace-text-list="{'TODAY':'今'}">
                </inline-calendar>
              </Popup>
            </div>
            <footer class="search" style="height: auto">
              <div class="selectBtn" @click="flightList">搜 索</div>
            </footer>
            <!--<search-history-->
              <!--:storageKey="searchHistoryKey"-->
              <!--@historyClick="inputCityVal"-->
              <!--ref="search-history"></search-history>-->
          </div>
        </div>
      </div>
    </section>
    <!--<bottom-navbar leftIcon="iconfont icon-guojijipiaodingdan"-->
                   <!--rightIcon="iconfont icon-hangbandongtai"-->
                   <!--leftTitle="机票订单"-->
                   <!--rightTitle="自助值机"-->
                   <!--@clickLeftBtn="flightOrderClick"-->
                   <!--@clickRightBtn="flightSelfClick"></bottom-navbar>-->
  </div>
</template>

<script>
//  import exchangeCity from '../../components/exchange-city'
//  import dateSelect from '../../components/date-select'
//  import headNav from '../../components/head.vue'
//  import { weeks } from '../../libs/weeker.js'
//  import searchHistory from './search-history'
//  import bottomNavbar from '../../components/bottom-navbar'
//  import backBtn from '../../components/backBtn.vue'
//  import { mapState, mapMutations, mapGetters, mapActions } from 'vuex'
  import { Popup, InlineCalendar, TransferDomDirective as TransferDom} from 'vux'

  const NOW_DATE = moment().format('YYYY-MM-DD');

  export default {
    name: 'flight',
    data () {
      return {
        startDate: NOW_DATE ,
        startDate2: NOW_DATE,
        popupFromCalendarVisible: false,
        popupToCalendarVisible: false,
        calendarFromData2: '' ,
        calendarToData2: '',
        go: '出发地',
        back: '目的地',
        date: '',//传给后台date
        date1: '请选择乘车日期',//页面上显示的日期
        searchHistoryKey:'searchFlightHistory'
      }
    },
    directives: {
      TransferDom
    },
    components: {
      Popup,
      InlineCalendar
//      searchHistory,
//      bottomNavbar,
//      backBtn,
//      exchangeCity,
//      dateSelect
    },
    methods: {
      //vux日历插件出发时间选择值
      onChangeFromDate(val) {
        this.$store.state.flight.fromDate = val;
        this.date = this.$store.state.flight.fromDate;
        this.startDate2 = val;
        // 老版本日历插件赋值
        this.$store.state.flight.openTime = val;
        // 判断往返时间
        let goTime = moment(this.$store.state.flight.fromDate).valueOf();
        let backTime = moment(this.$store.state.flight.returnTimes).valueOf()
        if(goTime >= backTime ) {
          this.$store.state.flight.returnTimes = moment(goTime + 86400000).format('YYYY-MM-DD');
          this.calendarToData2 = moment(goTime + 86400000).format('YYYY-MM-DD');
        }
        this.popupFromCalendarVisible = false;
      },
      //vux日历插件返回时间选择值
      onChangeToDate(val) {
        this.$store.state.flight.returnTimes = val
        this.popupToCalendarVisible = false;
      },
      flightOrderClick() {
        this.$router.push({
          path: 'common/all',
          query: {
            type: 'F'
          }
        })
      },
      flightSelfClick() {
        this.$vux.toast.show({
          type: 'text',
          text: '暂未开放',
          time: 2000
        })
        return
      },
      inputCityVal: function (item) {
        //点击机票时候只传id 不能传code
        var goDate = item.fromDate,   //出发时候的时间YYYY-MM-DD
          curTime = moment().format('YYYY-MM-DD'),
          curDate = +moment(),    //當前YYYY-MM-DD 換算成毫秒
          hisDate = +moment(goDate);           //歷史記錄   換算成毫秒
        //判断历史记录里面搜索出发的时间是否大于当前时间
        if(curDate < hisDate) {
          this.$store.state.flight.date1 = item.date1;
          this.$store.state.flight.fromDate = goDate;
          this.$store.state.flight.weekToday = item.weekToday;
          this.$store.state.flight.returnTimes = item.todate;  //返程
          this.calendarFromData2 = item.fromDate;  //控制去的日历插件时间变化
          this.calendarToData2 = item.todate;      //控制回来的日历插件时间变化
          this.$store.state.flight.openTime = goDate;  // 老版本日历active 时间状态
          this.$store.state.flight.toweeks = item.toweeks;
        } else{
          this.$store.state.flight.date1 = curTime.substring(5, 7) + '月' + curTime.substring(8, 10) + '日';
          this.$store.state.flight.weekToday = '今天';
          this.$store.state.flight.fromDate = moment(parseInt(curDate)).format('YYYY-MM-DD');
          this.$store.state.flight.fromDate = moment(this.$store.state.flight.fromDate).format('YYYY-MM-DD'); //只是处理脏数据的特殊情况
          this.$store.state.flight.returnTimes = moment(parseInt(curDate + 86400000)).format('YYYY-MM-DD');
          this.calendarFromData2 = curTime;  //控制去的日历插件时间变化
          this.$store.state.flight.openTime = moment().format('YYYY-MM-DD');  // 老版本日历插件赋值
          this.calendarToData2 = moment(parseInt(curDate + 86400000)).format('YYYY-MM-DD');      //控制回来的日历插件时间变化
        }

        this.$store.state.flight.go = item.fromCityName;
        this.$store.state.flight.back = item.toCityName;
        this.$store.state.flight.fromCityName = item.fromCityName;
        this.$store.state.flight.toCityName = item.toCityName;
        this.$store.state.flight.fromCityCode = item.fromCityCode;
        this.$store.state.flight.toCityCode = item.toCityCode;
        this.$store.state.flight.fromCityId = item.fromCityId;
        this.$store.state.flight.toCityId = item.toCityId;
        this.$store.state.flight.isTripState = item.isTripState;
      },
      //切换往返程
      setistrip (istrip) {
        let code = this.$store.state.flight.isTripState
        if (code == istrip) return
        this.$store.state.flight.isTripState = istrip
        if (istrip == 1) {
          this.$store.state.flight.openTime = this.$store.state.flight.fromDate
        } else if (istrip == 2) {
          var timeCuo = +moment(this.$store.state.flight.fromDate) + 86400000
          this.$store.state.flight.returnTimes = timeCuo.cuoChangeTime()
        }
      },
      //判断点击是去还说返
      show_data (num) {
        if (num === 1) {
          if (this.istrip == 1) {
            this.$router.push({
              path: 'flightDate',
              query: {
                back: 'flightIndex',
                goal: '去程'
              }
            })
          }
          if (this.istrip == 2) {
            this.$router.push({
              path: 'flightDateTwo',
              query: {
                back: 'flightIndex',
              }
            })
          }
        } else if (num === 2) {
          this.$router.push({
            path: 'flightDateTwo',
            query: {
              back: 'flightIndex',
            }
          })
        }
      },
      cityVue (i) {
        var that = this
        that.$router.push({
          path: '/flight/city',
          query: {
            go: i
          }
        })
      },
      change (index) {
        var store = this.$store.state.flight;
        if(store.go !== '出发地' && store.back !== '目的地') {
          var change, change1,city, city1;
          change = this.$store.state.flight.go;
          city = this.$store.state.flight.fromCityName;
          this.$store.state.flight.go = this.$store.state.flight.back;
          this.$store.state.flight.fromCityName = this.$store.state.flight.toCityName;
          this.$store.state.flight.back = change;
          this.$store.state.flight.toCityName = city;
          change1 = this.$store.state.flight.fromCityCode;
          city1 = this.$store.state.flight.fromCityId;
          this.$store.state.flight.fromCityCode = this.$store.state.flight.toCityCode;
          this.$store.state.flight.fromCityId = this.$store.state.flight.toCityId;
          this.$store.state.flight.toCityCode = change1;
          this.$store.state.flight.toCityId = city1;
        }
      },
      flightList () {
        var that = this
        that.showPositionValue = true;
        //拼接几月几号星期几moment()
        that.$store.state.flight.month = that.$store.state.flight.fromDate.substring(5, 7)
        that.$store.state.flight.day = that.$store.state.flight.fromDate.substring(8, 10)
        let godate = parseInt(+moment(this.$store.state.flight.fromDate))
        let todate = parseInt(+moment(this.$store.state.flight.returnTimes))

        if (that.$store.state.flight.go == '出发地' || that.$store.state.flight.go == '目的地' || that.$store.state.flight.back == '目的地' || that.$store.state.flight.back == '出发地') {
          that.$vux.toast.show({
            type: 'text',
            text: '信息填写不完整',
            time: 2000
          })
          return
        } else if (that.$store.state.flight.go == that.$store.state.flight.back || that.$store.state.flight.fromCityName == that.$store.state.flight.toCityName) {
          that.$vux.toast.show({
            type: 'text',
            text: '出发城市不能和到达城市相同',
            time: 2000
          })
          return
        }
        if (this.istrip == 2) {//往返
          if (!this.$store.state.flight.returnTimes) {
            that.$vux.toast.show({
              type: 'text',
              text: '返程时间不能为空',
              time: 2000
            })
            return
          } else if (godate > todate && this.istrip === 2) {
            that.$vux.toast.show({
              type: 'text',
              text: '返程时间不能小于去程',
              time: 2000
            })
            return
          } else {
            //存放在历史记录里面的值
            var curSearch = {
              'go': that.$store.state.flight.go,   //显示的出发地方
              'back': that.$store.state.flight.back, //显示的返回地方
              'fromDate': that.$store.state.flight.fromDate, //出发时间
              'fromCityName': that.$store.state.flight.fromCityName,  //历史记录对应的城市
              'toCityName': that.$store.state.flight.toCityName,  //历史记录对应的城市
              'fromCityId': that.$store.state.flight.fromCityId,  //历史记录对应的id
              'toCityId': that.$store.state.flight.toCityId,  //历史记录对应的id
              'currentDate': that.$store.state.flight.currentDate,  //当前日期
              'isTripState': that.$store.state.flight.isTripState,  //单程还是返程，默认1 单程
              'date1': that.$store.state.flight.date1,
              'fromDate': that.$store.state.flight.fromDate,
              'fromCityCode': that.$store.state.flight.fromCityCode,  //去的城市编码
              'toCityCode': that.$store.state.flight.toCityCode,
              'weekToday': that.$store.state.flight.weekToday,
              'todate': that.$store.state.flight.returnTimes,  //返程日期
              'toweeks': that.$store.state.flight.toweeks //返程星期几
            };
            that.$refs['search-history'].addHistory(curSearch);
            that.$router.push({
              path: '/flight/toflightList',
              query: {
                from: '/flight/flightIndex',
                fligthstate: that.$store.state.flight.isTripState,
                state: 'go'
              }
            })
          }
        }
        else if (this.istrip == 1) {
          that.$vux.loading.show({
            text: '加载中...'
          })
          // 出发时间
          this.$flight.getFlightList({
            fromCityCode: this.$store.state.flight.fromCityCode,
            toCityCode: this.$store.state.flight.toCityCode,
            fromCityId: this.$store.state.flight.fromCityId,
            toCityId: this.$store.state.flight.toCityId,
            fromDate: this.$store.state.flight.fromDate,
            fromType: this.$store.state.flight.fromType,
            toType: this.$store.state.flight.toType,
            sort: 'date_early',
            isFilter: true
          }, function (res) {
            that.$vux.loading.hide();
            if (res.code !== '0' && res.code !== '2') {
              //存放在历史记录里面的值
              var curSearch = {
                'go': that.$store.state.flight.go,   //显示的出发地方
                'back': that.$store.state.flight.back, //显示的返回地方
                'fromDate': that.$store.state.flight.fromDate, //出发时间
                'fromCityName': that.$store.state.flight.fromCityName,  //历史记录对应的城市
                'toCityName': that.$store.state.flight.toCityName,  //历史记录对应的城市
                'fromCityId': that.$store.state.flight.fromCityId,  //历史记录对应的id
                'toCityId': that.$store.state.flight.toCityId,  //历史记录对应的id
                'currentDate': that.$store.state.flight.currentDate,  //当前日期
                'isTripState': that.$store.state.flight.isTripState,  //单程还是返程，默认1 单程
                'date1': that.$store.state.flight.date1,
                'fromCityCode': that.$store.state.flight.fromCityCode,  //去的城市编码
                'toCityCode': that.$store.state.flight.toCityCode,
                'weekToday': that.$store.state.flight.weekToday,
                'todate': that.$store.state.flight.returnTimes,  //返程日期
                'toweeks': that.$store.state.flight.toweeks //返程星期几
              };
              that.$refs['search-history'].addHistory(curSearch);
            }
            if (res.code === '0' || res.code === '2') { //查询返回数据为空 0  查询异常  2
              that.$vux.toast.show({
                type: 'text',
                text: res.message,
                time: 3000,
                width: '65%'
              })
              return
            } else if (res.code === '1' || res.code === '8') {  //根据差旅政策过滤后为空 1
              that.$store.state.flight.noFlight = true
              that.$store.state.flight.noFlightInfo = res.message
            } else {
              that.$store.state.flight.noFlight = false
            }
            //详细所有航班列表
            that.$store.state.flight.flightShowDetail = res.flightListForm[0].flightShowDetail
            that.$store.state.flight.flightForm = res.flightListForm[0].flightForm
            //星期列表
            that.$store.state.flight.week = res.week
            for (var i = 0; i < that.$store.state.flight.week.length; i++) {
              if (that.$store.state.flight.week[i].flag == true) {
                that.$store.state.flight.Sunday = '周' + that.$store.state.flight.week[i].week
                that.$store.state.flight.selected = that.$store.state.flight.week[i].id
              }
            }
            //出发机场
            that.$store.state.flight.fromCityForms = res.fromCityForms
            //到达机场
            that.$store.state.flight.toCityForms = res.toCityForms
            // 机型
            that.$store.state.flight.aircraftTypes = res.aircraftTypes
            // 航空公司
            that.$store.state.flight.carrierForms = res.carrierForms
            //折扣转换
            that.$store.state.flight.cabinTypeMap = res.cabinTypeMap
            //res.cabinTypeMap  :   1: "特价"2:"全价"3:"高端"4:"折扣"5:"超值"6:"优享"7:"超级"8:"豪华"9:"明珠折扣"10:"明珠"11:"特殊"12:"舒适"

            //舱位转换
            that.$store.state.flight.cabinGradeMap = res.cabinGradeMap
            //res.cabinGradeMap :  C:"公务舱"F:"头等舱"Y:"经济舱"
            //筛选数据重组
            var state = that.$store.state
            //出发机场
            state.flight.fromCityForms = res.fromCityForms
            //到达机场
            state.flight.toCityForms = res.toCityForms
            //机型
            state.flight.aircraftTypes = res.aircraftTypes
            //航空公司
            state.flight.carrierForms = res.carrierForms
            //折扣转换
            state.flight.cabinTypeMap = res.cabinTypeMap
            //舱位转换
            state.flight.cabinGradeMap = res.cabinGradeMap

            var fromTime = state.flight.fromTimes.split(',')
            var fromAirportNames = state.flight.fromAirportNames.split(',')
            var toAirportNames = state.flight.toAirportNames.split(',')
            var aircrafts = state.flight.aircrafts.split(',')
            var carrierNameShorts = state.flight.carrierNameShorts.split(',')
            //综合筛选数据重组
            for (var i = 0; i < state.flight.tabInfo.length; i++) {
              switch (i) {
                case 0://起飞时间
                  if (fromTime[0] != '') {
                    for (var k = 0; k < fromTime.length; k++) {
                      for (var j = 0; j < state.flight.tabInfo[i].tabInfos.length; j++) {
                        if (fromTime[k] == state.flight.tabInfo[i].tabInfos[j].listName) {
                          state.flight.tabInfo[i].tabInfos[j].a = true
                        }
                      }
                    }
                    state.flight.tabInfo[i].tabInfos[0].a = false
                  }
                  break
                case 1: //出发机场
                  that.$store.commit('CLEAR_FLIGHT_GO_CITY_NAME', []);
                  for (var j = 0; j < state.flight.fromCityForms.length; j++) {
                    var obj = {}
                    obj.fromAirport = state.flight.fromCityForms[j].fromAirport
                    obj.a = state.flight.fromCityForms[j].checked;
                    state.flight.tabInfo[i].tabInfos.push(obj)
                  }
                  if (fromAirportNames[0] != '') {
                    for (var k = 0; k < fromAirportNames.length; k++) {
                      for (var j = 0; j < state.flight.tabInfo[i].tabInfos.length; j++) {
                        if (fromAirportNames[k] == state.flight.tabInfo[i].tabInfos[j].fromAirport) {
                          state.flight.tabInfo[i].tabInfos[j].a = true
                        }
                      }
                    }
                    state.flight.tabInfo[i].tabInfos[0].a = false
                  }
                  break
                case 2:  //到达机场
                  that.$store.commit('CLEAR_FLIGHT_BACK_CITY_NAME', []);
                  for (var j = 0; j < state.flight.toCityForms.length; j++) {
                    var obj = {}
                    obj.toAirport = state.flight.toCityForms[j].toAirport
                    obj.a = state.flight.toCityForms[j].checked;
                    state.flight.tabInfo[i].tabInfos.push(obj)
                  }
                  if (toAirportNames[0] != '') {
                    for (var k = 0; k < toAirportNames.length; k++) {
                      for (var j = 0; j < state.flight.tabInfo[i].tabInfos.length; j++) {
                        if (toAirportNames[k] == state.flight.tabInfo[i].tabInfos[j].toAirport) {
                          state.flight.tabInfo[i].tabInfos[j].a = true
                        }
                      }
                    }
                    state.flight.tabInfo[i].tabInfos[0].a = false
                  }
                  break
                case 3:  //机型
                  for (var j = 0; j < state.flight.aircraftTypes.length; j++) {
                    var obj = {}
                    obj.aircrefTypeName = state.flight.aircraftTypes[j].aircrefTypeName
                    obj.aircrefType = state.flight.aircraftTypes[j].aircrefType
                    obj.a = false
                    state.flight.tabInfo[i].tabInfos.push(obj)
                  }
                  if (aircrafts[0] != '') {
                    for (var k = 0; k < aircrafts.length; k++) {
                      for (var j = 0; j < state.flight.tabInfo[i].tabInfos.length; j++) {
                        if (aircrafts[k] == state.flight.tabInfo[i].tabInfos[j].aircrefType) {
                          state.flight.tabInfo[i].tabInfos[j].a = true
                        }
                      }
                    }
                    state.flight.tabInfo[i].tabInfos[0].a = false
                  }
                  break
                case 4:  //航空公司
                  for (var j = 0; j < state.flight.carrierForms.length; j++) {
                    var obj = {}
                    obj.carrierName = state.flight.carrierForms[j].carrierName
                    obj.a = false
                    state.flight.tabInfo[i].tabInfos.push(obj)
                  }
                  if (carrierNameShorts[0] != '') {
                    for (var k = 0; k < carrierNameShorts.length; k++) {
                      for (var j = 0; j < state.flight.tabInfo[i].tabInfos.length; j++) {
                        if (carrierNameShorts[k] == state.flight.tabInfo[i].tabInfos[j].carrierName) {
                          state.flight.tabInfo[i].tabInfos[j].a = true
                        }
                      }
                    }
                    state.flight.tabInfo[i].tabInfos[0].a = false
                  }
                  break
              }
            }
            //控制排序方式保存后初始化
            for (var i = 0; i < that.popInfo.length; i++) {//排序
              that.$store.state.flight.popInfo[i].isSelected = false
              that.$store.state.flight.popInfo[i].popShowCheck = false
            }
            that.$store.state.flight.popInfo[1].isSelected = true
            that.$store.state.flight.popInfo[1].popShowCheck = true
            for (var i = 0; i < that.popInfo1.length; i++) {//舱位
              that.$store.state.flight.popInfo1[i].isSelected = false
              that.$store.state.flight.popInfo1[i].popShowCheck = false
            }
            that.$store.state.flight.popInfo1[2].isSelected = true
            that.$store.state.flight.popInfo1[2].popShowCheck = true
            for (var i = 0; i < that.tabInfo.length; i++) {//综合筛选
              for (var j = 0; j < that.tabInfo[i].tabInfos.length; j++) {
                that.tabInfo[i].tabInfos[j].a = false
              }
            }
            //筛选条件初始化
            that.$store.state.flight.sort = 'date_early'//时间和价格排序方式  默认为从早到晚:date_early 价格从低到高price_down
            that.$store.state.flight.code = '',//F:头等舱   C:公务舱     Y:经济舱this.$store.state.flight.fromTimes='';that.$store.state.flight.fromAirportNames = ''
              that.$store.state.flight.toAirportNames = ''
            that.$store.state.flight.aircrafts = ''
            that.$store.state.flight.carrierNameShorts = ''
            that.$store.state.flight.travelPolicyCheck = true
            //路由跳转
            that.$router.push({
              path: '/flight/flightList',
              query: {
                from: 'flightIndex',
                fligthstate: that.$store.state.flight.isTripState,
                state: 'go'
              },
            })

          },function (err) {
            that.$vux.loading.hide();
            $flightTools.errorToIndex(that);
          });
        }
      },
    },
    mounted () {
      //对时间操作  获取基础时间
      var nowDate = moment().format('YYYY-MM-DD');
      //传给后台的时间
      var currentdate = nowDate;
      this.$store.state.flight.currentDate = currentdate

      var returnDate = this.$store.state.flight.returnTimes;
      var currentDate = this.$store.state.flight.fromDate;
      if(!returnDate) {
        returnDate = moment().add(1, 'd').format('YYYY-MM-DD');
      }
      if(!currentDate) {
        currentDate = moment().format('YYYY-MM-DD');;
      }
      this.calendarToData2 = returnDate;
      this.calendarFromData2 = currentDate;

      //页面显示时间
      if (this.$store.state.flight.onlyOne == 1) {
        // 一上来默认给今天时间 传给后台
        this.date = currentdate
        this.$store.state.flight.onlyOne = 2
        //出发时间
        this.$store.state.flight.fromDate = this.date
      } else {
        this.date = this.$store.state.flight.fromDate
      }

      //获取首页差旅计划传递的数据
      var fromCity = this.$route.query.fromCity,
        toCity = this.$route.query.toCity,
        fromCityCode = this.$route.query.fromCityCode,
        toCityCode =  this.$route.query.toCityCode,
        fromCityId = this.$route.query.fromCityId,
        toCityId =  this.$route.query.toCityId,
        fromDate = this.$route.query.fromDate;
      //mock 时间
      if(fromDate && +moment(currentdate) < +moment(fromDate)) {
        this.date = fromDate
        this.$store.state.flight.fromDate = fromDate;
        this.$store.state.flight.openTime = fromDate;
      } else {
        this.date = this.$store.state.flight.fromDate;
        this.$store.state.flight.openTime = moment().format('YYYY-MM-DD');
      };
      if(fromCity && toCity) {
        this.$store.state.flight.go = fromCity;
        this.$store.state.flight.fromCityName = fromCity;
        this.$store.state.flight.back = toCity;
        this.$store.state.flight.toCityName = toCity;
      }
      if(fromCityCode) this.$store.state.flight.fromCityCode = fromCityCode;
      if(toCityCode) this.$store.state.flight.toCityCode = toCityCode;
      if(fromCityId) this.$store.state.flight.fromCityId = fromCityId;
      if(toCityId) this.$store.state.flight.toCityId = toCityId;
    },
    watch: {
      date (val, oldVal) {
        var year = this.date.substring(0, 4)
        var mouth = this.date.substring(5, 7)
        var day = this.date.substring(8, 10)
        this.$store.state.flight.date1 = mouth + '月' + day + '日';
        this.$store.state.flight.weekToday = weeks(this.date);
      }
    },
    computed: {
      endDate() {
        return moment().add(1, 'Y').add(1, 'd').format('YYYY-MM-DD');
      },
      calendarFromData() {
        return this.$store.state.flight.date1;
      },
      weekFromData() {
        return this.$store.state.flight.weekToday;
      },
      logoutConfirmShow () {
        return false
      },
      cityGoClassObj() {
        return this.cityGo =='出发地' || this.cityGo == '目的地' ? 'goBackActive' : ''
      },
      cityBackClassObj() {
        return this.cityBack =='出发地'|| this.cityBack == '目的地' ? 'goBackActive' : ''
      },
      cityGo() {
        return this.$store.state.flight.go;
      },
      cityBack() {
        return this.$store.state.flight.back;
      },
      fromTimes () {
        return this.$store.state.flight.fromTimes
      }, //出发时间参数
      fromAirportNames () {
        return this.$store.state.flight.fromAirportNames
      },//出发机场参数
      toAirportNames () {
        return this.$store.state.flight.toAirportNames
      },//到达机场参数
      aircrafts () {
        return this.$store.state.flight.aircrafts
      },//机型参数
      carrierNameShorts () {
        return this.$store.state.flight.carrierNameShorts
      },//航空公司参数
      tab () {
        return this.$store.state.tab
      },
      popInfo () {
        return this.$store.state.flight.popInfo
      },
      popInfo1 () {
        return this.$store.state.flight.popInfo1
      },
      tabInfo () {
        return this.$store.state.flight.tabInfo
      },
      fromCityForms () {
        return this.$store.state.flight.fromCityForms
      },
      toCityForms () {
        return this.$store.state.flight.toCityForms
      },
      aircraftTypes () {
        return this.$store.state.flight.aircraftTypes
      },
      carrierForms () {
        return this.$store.state.flight.carrierForms
      },
      flight () {
        return this.$store.state.flight
      },
      //计算单程还说返程
      istrip () {
        return this.$store.state.flight.isTripState
      },
      //计算返程年月
      todate () {
        let date = this.$store.state.flight.returnTimes;
        let yue, tian
        if (date !== '') {
          yue = `${date.substring(5, 7)}月`
          tian = `${date.substring(8, 10)}日`
          this.$store.state.flight.todate = `${yue}${tian}`
        } else {
          this.$store.state.flight.todate = '返程时间'
        }
        return this.$store.state.flight.todate
      },
      //计算返程星期
      toweeks () {
        let date = this.$store.state.flight.returnTimes;
        let dateTime = moment(date);
        let time = moment().format('YYYY-MM-DD'); //YYYY-MM-DD
        if (date !== '') {
          if((+moment(time)) < moment(date).valueOf() &&  moment(date).valueOf() <= +moment(time) + 86400000) {
            this.$store.state.flight.toweeks = '明天'
          }else {
            this.$store.state.flight.toweeks = weeks(date)
          }

        }
        return this.$store.state.flight.toweeks
      }
    }
  }
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  body, html {
    width: 100%;
    height: 100%;
    background-color: #f8f8f8;
  }
  .outer {
    width: 100%;
    height: 100%;
    background-color: #f8f8f8;
  }
  .main {
    margin-bottom: 4rem;
  }
  .item {
    box-sizing: border-box;
    height: 3rem;
    font-size: 1rem;
    input[type=text] {
      height: 3rem;
      font-size: 1rem;
      line-height: 3rem;
    }
  }
  .active {
    border-bottom: 1px solid #0094db;
  }
  .icon-fanhui {
    font-size: 3rem;
    color: #FFFFFF;
    line-height: 2rem;
  }
  .ico {
    font-size: 1.5rem;
    color: #0094db;
  }
  .search {
    padding-bottom: 1rem;
  }
  .selectBtn {
    margin: 2rem auto 0;
    display: block;
    width: 95%;
    height: 2.5rem;
    background-color: #46a1bb;
    font-size:1rem;
    text-align: center;
    color: #fff;
    line-height: 2.5rem;
    border-radius: 1.25rem;
  }
  .banner img {
    width: 100%;
  }
  .listInfo {
    position: relative;
    margin-top: -2.64rem;
    margin-left: 3%;
    width: 94%;
    border-radius: .5rem;
  }
  .planeInfo {
    padding-bottom: .8rem;
    border-bottom-left-radius: .5rem;
    border-bottom-right-radius: .5rem;
    background-color: #FFFFFF;
  }
  .way-and-reutren {
    display: flex;
    height: 2.5rem;
    box-sizing: border-box;
    line-height: 2.5rem;
    font-size: .8rem;
    & > div {
      flex: 1;
      text-align: center;
    }
    &  span {
      display: inline-block;
      width: 100%;
      height: 100%;
      color: #FFFFFF;
      background-color: rgba(0, 0, 0, .3);
      border-top-left-radius: .5rem;
      border-top-right-radius: .5rem;
    }
    & span.spanaactive {
      background-color: rgba(255, 255, 255, 1);
      color: #333333;
    }
  }
  .banner span img {
    width: 35%;
    margin: 0 auto;
  }
</style>
